package top.ucat.x.service.sso.server.controller.management;


import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ucat.box.cloud.common.result.Result;
import top.ucat.box.cloud.common.result.SystemResult;
import top.ucat.box.starter.oauth.common.annotation.Ignore;
import top.ucat.x.sso.service.provider.LoginService;

@RestController
@RequestMapping("login")
public class LoginController {


    @Reference
    private LoginService loginService;

    @Ignore
    @PostMapping
    public Result loginByUsernameAndPassword(String username, String password) throws HttpRequestMethodNotSupportedException {
        OAuth2AccessToken token = loginService.loginByUsernameAndPassword(username, password);
        return SystemResult.OK.getResult(token);
    }
}
